﻿using System;
using System.Windows.Forms;
using Game;

namespace Memory.WindowsUI
{
    public class CardButton : Button 
    {
        public event EventHandler CardChangedStaus;

        private Board.Coordinate m_Coordinates;
        private Card m_CardPointer;

        public CardButton(int i_RowIndex, int i_ColIndex, Board i_Board)
        {
            m_Coordinates = new Board.Coordinate(i_RowIndex, i_ColIndex);
            m_CardPointer = i_Board.GetCard(m_Coordinates);
            m_CardPointer.ChangedStatus += new EventHandler(CardPointer_ChangedStatus);
        }

        public Card CardPointer
        {
            get { return m_CardPointer; }
            set { m_CardPointer = value; }
        }

        public void ToggleText(bool i_IsVisible)
        {
            if (!i_IsVisible)
            {
                this.Text = string.Empty;
            }
            else
            {
                this.Text = m_CardPointer.Symbol.ToString();
            }
        }

        private void CardPointer_ChangedStatus(object sender, EventArgs e)
        {
            if (CardChangedStaus != null)
            {
                CardChangedStaus(this, e);
            }
        }

        public Board.Coordinate Coordinates
        {
            get { return m_Coordinates; }
            set { m_Coordinates = value; }
        }
    }
}
